<template>
  <navbar title="成绩" :isBack="true"></navbar>
  <search :title="info.title" placeholder="输入证件号" @change="change"></search>
  <view class="line"></view>
  <!-- 查询结果 -->
  <view class="result flex-direction-column" v-if="info.params.key_word && info.form">
    <view class="item flex-direction-column">
      <view class="title">查询结果</view>
      <view class="score">
        <view class="t2 flex">赛事成绩</view>
        <view class="pic">
          <view class="mess flex-direction-column">
            <view class="name">{{ info.form.active }}</view>
            <view class="time">{{ info.form.achievement }}</view>
            <view class="num">第{{ info.form.rank }}名</view>
            <view class="desc flex-space-between">
              <view class="item flex-direction-column">
                <text>{{ info.form.name }}</text>
                <text>姓名</text>
              </view>
              <view class="item flex-direction-column">
                <text>{{ info.form.number }}</text>
                <text>参赛号</text>
              </view>
              <view class="item flex-direction-column">
                <text>{{ info.form.group }}</text>
                <text>组别名称</text>
              </view>
            </view>
          </view>
          <image src="/pagesA/static/image/23.png"></image>
        </view>
      </view>
    </view>
    <view class="line"></view>
    <view class="item">
      <view class="score">
        <view class="t2 flex">成绩证书</view>
        <view class="score">
          <image mode="widthFix" style="width: 100%" :src="info.form.url"></image>
        </view>
        <view class="down flex" @click="tools.downImage(info.form.url)">
          <image src="/pagesA/static/image/24.png"></image>
          <text>下载证书</text>
        </view>
      </view>
    </view>
  </view>

  <picture
    v-else
    bg="#fff"
    :title="lack[lackIndex].title"
    :imgPath="lack[lackIndex].imgPath"
    :imgHeight="lack[lackIndex].imgHeight"
    :imgWidth="lack[lackIndex].imgWidth"
    :height="tools.clientTopHight(140)"
  ></picture>
</template>

<script setup lang="ts">
import { reactive, ref } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import { getAchievement, getSearchResult } from '@/service/api/index'
import tools from '@/utils/tools'
import search from '@/common/menu/query.vue'
// import picture from '@/components/lack/picture.vue'

const lack = [
  {
    imgWidth: '334rpx',
    imgHeight: '192rpx',
    title: '您还未查询，请输入关键词查询吧~',
    imgPath: '/pagesA/static/image/21.png'
  },
  {
    imgWidth: '360rpx',
    imgHeight: '200rpx',
    title: '暂无查询结果',
    imgPath: '/pagesA/static/image/22.png'
  }
]

let lackIndex = ref(0)
let info = reactive({
  title: '',
  params: {
    id: 0,
    key_word: ''
  },
  form: null
})

const change = (e) => {
  info.params.key_word = e
  // 查询
  getSearchResultApi()
}

// 页面数据
const getAchievementApi = async (id) => {
  const { msg } = await getAchievement({ id })
  info.params.id = msg.id
  info.title = msg.name
}

// 查询
const getSearchResultApi = async () => {
  const { msg } = await getSearchResult(info.params)
  if (!msg) return (lackIndex.value = 1)
  info.form = msg
  console.log(info.form)
}

onLoad((option) => {
  // 页面数据
  getAchievementApi(option.id)
})
</script>

<style lang="scss" scoped>
.t2 {
  border: none !important;
}
.result {
  .item {
    padding: 24rpx 26rpx 32rpx 26rpx;
  }
  .title {
    font-size: 32rpx;
    font-weight: bold;
    line-height: 44rpx;
    text-align: center;
    padding-bottom: 26rpx;
    border-bottom: 1px solid #eee;
  }
  .score {
    margin-top: 36rpx;
    .pic {
      width: 100%;
      height: 352rpx;
      position: relative;
      image {
        width: 100%;
        height: 100%;
      }
      .mess {
        left: 0;
        right: 0;
        width: 600rpx;
        height: 100%;
        margin: 0 auto;
        position: absolute;
        align-items: center;
        justify-content: center;
        .name {
          font-size: 32rpx;
          margin-top: 50rpx;
          font-weight: bold;
          line-height: 44rpx;
        }
        .time {
          height: 58rpx;
          font-size: 48rpx;
          font-weight: bold;
          line-height: 58rpx;
          margin-top: 20rpx;
          color: #e6425e;
        }
        .num {
          height: 40rpx;
          font-size: 28rpx;
          font-weight: bold;
          color: #c59053;
          margin-top: 18rpx;
          line-height: 40rpx;
        }
        .desc {
          width: 100%;
          margin-top: 42rpx;
          .item {
            text-align: center;
            text {
              &:nth-child(1) {
                height: 34rpx;
                font-size: 24rpx;
                line-height: 34rpx;
              }
              &:nth-child(2) {
                height: 28rpx;
                color: #777777;
                font-size: 20rpx;
                line-height: 28rpx;
              }
            }
          }
        }
      }
    }
  }
  .down {
    height: 58rpx;
    width: 200rpx;
    margin: 80rpx auto 40rpx auto;
    background-color: #e6425e;
    border-radius: 6rpx;
    image {
      width: 28rpx;
      height: 28rpx;
      margin-left: 22rpx;
      margin-right: 10rpx;
    }
    text {
      font-size: 28rpx;
      color: #ffffff;
    }
  }
}
</style>
